package fhp.hlhj.giantfold.activity.message

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.adapter.MessageCenterListAdp
import fhp.hlhj.giantfold.interfaces.IMessageCenter
import fhp.hlhj.giantfold.javaBean.MessageCenterBean
import fhp.hlhj.giantfold.presenter.MessageCenterPresenter
import kotlinx.android.synthetic.main.activity_active_message_aty.*

class MessageAty : BaseActivity(), IMessageCenter {
    private lateinit var datas:ArrayList<String>
    private lateinit var presenter:MessageCenterPresenter
    private lateinit var listAdp:MessageCenterListAdp
    override fun getContentId(): Int = R.layout.activity_message_aty

    override fun initView() {

        presenter= MessageCenterPresenter(this)
        val params = HttpParams()
        params.put("user_id",Contents.userId)
        presenter.getMessge(params)
    }
    override fun initData() {
        recyclerview.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)

    }

    override fun initListener() {

        btExit.setOnClickListener {
            finish()
        }

    }

    override fun showLoading() {
        loadingDialog.show()
    }

    override fun onResp(messageCenterBean: MessageCenterBean) {
        loadingDialog.dismiss()
        if (messageCenterBean.code==200){
            val list = java.util.ArrayList<MessageCenterBean>()
            list.add(messageCenterBean)
            list.add(messageCenterBean)
            listAdp= MessageCenterListAdp(R.layout.message_center_item,list)
            recyclerview.adapter=listAdp
        }
        listAdp.setOnItemClickListener { adapter, view, position ->
            val intent = Intent(this@MessageAty, ActiveMessageAty::class.java)
            intent.putExtra("type",when(position){0->{"1"}1->{"2"}else->{"1"}})
            startActivity(intent)
        }
    }
}
